#!/usr/bin/env python
# -*- coding: utf-8 -*-
#

import unittest

from jute.db import Memtable, ColumnFamily, Column
from jute.db import QueryPath, NamesQueryFilter

class   MemtableTestCase(unittest.TestCase) :
    def setUp(self) :
        pass
        ## setUp()

    def tearDown(self) :
        pass
        ## tearDown()

    def testGetColumnWithNamesQueryFilter(self) :
        table = None
        cfname = 'testCF'
        cf = ColumnFamily(cfname)
        c1 = Column('col1','val1',1)
        c2 = Column('col2','val2',1)
        c3 = Column('col3','val3',1)
        for c in (c1, c2, c3) :
            cf.addColumn( c )

        row_key = 'TestKEY'
        mt = Memtable(table, cfname)
        mt.put(row_key, cf)

        query_path = QueryPath(column_family_name = cfname)
        query_filter = NamesQueryFilter(row_key, query_path, ('col1',))
        iterator = mt.getNamesIterator( query_filter )
        cf = iterator.getColumnFamily()
        self.assertEqual(cf.name, cfname)
        c = iterator.next()
        self.assertEqual(c, c1)

        query_filter = NamesQueryFilter(row_key, query_path, ('col1','col2'))
        iterator = mt.getNamesIterator( query_filter )
        cf = iterator.getColumnFamily()
        self.assertEqual(cf.name, cfname)
        c = iterator.next()
        self.assertEqual(c, c1)
        c = iterator.next()
        self.assertEqual(c, c2)

        query_filter = NamesQueryFilter(row_key, query_path, ('col3',))
        iterator = mt.getNamesIterator( query_filter )
        cf = iterator.getColumnFamily()
        self.assertEqual(cf.name, cfname)
        c = iterator.next()
        self.assertEqual(c, c3)


        ## testGetColumnWithNamesQueryFilter()

    ## class MemtableTestCase


if __name__ == '__main__' :
    unittest.main()

